//
//  RGSearchVedioCell.m
//  RedGrass
//
//  Created by wukong on 2019/2/13.
//  Copyright © 2019年 hongcaosp. All rights reserved.
//

#import "RGSearchVedioCell.h"
#import <UIImageView+WebCache.h>

@interface RGSearchVedioCell()

@property (strong, nonatomic) UIImageView *vedioBackImg;
@property (strong, nonatomic) UILabel *contentLabel;
@property (strong, nonatomic) UIImageView *userImg;
@property (strong, nonatomic) UILabel *nickName;
@property (strong, nonatomic) UILabel *countLabel;
@property (strong, nonatomic) UIImageView *favoriteImg;

@end

@implementation RGSearchVedioCell

-(instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
      
        [self initSubView];
    }
    return self;
}

-(void)initSubView{
    [self.contentView addSubview:self.vedioBackImg];
    [_vedioBackImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
    
    [self.contentView addSubview:self.userImg];
    [_userImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(30, 30));
        make.left.mas_equalTo(self.contentView).mas_offset(4);
        make.bottom.mas_equalTo(self.contentView).mas_offset(-4);
    }];
    
    [self.contentView addSubview:self.nickName];
    [_nickName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.userImg.mas_centerY).mas_offset(0);
        make.left.mas_equalTo(self.userImg.mas_right).mas_offset(4);
    }];
    
    [self.contentView addSubview:self.countLabel];
    [_countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.userImg.mas_centerY).mas_offset(0);
        make.right.mas_equalTo(self.contentView).mas_offset(-6);
    }];
    
    [self.contentView addSubview:self.favoriteImg];
    [_favoriteImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.userImg.mas_centerY).mas_offset(0);
        make.right.mas_equalTo(self.countLabel.mas_left).mas_offset(-2);
        make.size.mas_equalTo(CGSizeMake(10, 10));
    }];

    [self.contentView addSubview:self.contentLabel];
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.userImg.mas_left).mas_offset(0);
        make.bottom.mas_equalTo(self.userImg.mas_top).mas_offset(-7);
        make.right.mas_equalTo(self.contentView).mas_offset(-20);
    }];
}

#pragma mark - public
-(void )setModel:(RGRecommendVideoModel *)model{
    if(model == nil){
        return;
    }
    _model = model;
    [_vedioBackImg sd_setImageWithURL:[NSURL URLWithString:SafeStr(model.coverPath)]];
    _nickName.text = SafeStr(model.videoUser.nickname);
    [_userImg sd_setImageWithURL:[NSURL URLWithString:SafeStr(model.videoUser.image)] placeholderImage:IMAGE_NAMED(@"头像1")];
    _contentLabel.text = model.videoDesc;
    _countLabel.text = [self makeCountStrWithNumber:model.likeCounts];
}


-(NSString *)makeCountStrWithNumber:(NSInteger)num{
    if(num < 10000){
        return [NSString stringWithFormat:@"%ld",num];
    }
    float tempNum = num / 10000;
    return [NSString stringWithFormat:@"%0.1fW",ceil(tempNum)];
}


#pragma mark - getter

-(UIImageView *)vedioBackImg{
    if(!_vedioBackImg){
        _vedioBackImg = [[UIImageView alloc]init];
        _vedioBackImg.backgroundColor = [UIColor whiteColor];
    }
    return _vedioBackImg;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [[UILabel alloc]init];
        _contentLabel.textColor = [UIColor whiteColor];
        _contentLabel.font = FONT(customFontName, 12);
        _contentLabel.numberOfLines = 3;
    }
    return _contentLabel;
}

-(UIImageView *)userImg{
    if(!_userImg){
        _userImg = [[UIImageView alloc]init];
        _userImg.image = IMAGE_NAMED(@"头像1");
        ViewRadius(_userImg, 15);
    }
    return _userImg;
}

-(UILabel *)nickName{
    if(!_nickName){
        _nickName = [[UILabel alloc]init];
        _nickName.textColor = [UIColor whiteColor];
        _nickName.font = FONT(customFontName, 12);
    }
    return _nickName;
}

-(UILabel *)countLabel{
    if(!_countLabel){
        _countLabel = [[UILabel alloc]init];
        _countLabel.textColor = [UIColor whiteColor];
        _countLabel.font = FONT(customFontName, 12);
    }
    return _countLabel;
}

-(UIImageView *)favoriteImg{
    if(!_favoriteImg){
        _favoriteImg = [[UIImageView alloc]init];
        _favoriteImg.image = IMAGE_NAMED(@"动态_点赞");
    }
    return _favoriteImg;
}




@end
